<!DOCTYPE html><html lang="zh-CN" data-theme="light"><head><meta charset="UTF-8"><meta http-equiv="X-UA-Compatible" content="IE=edge"><meta name="viewport" content="width=device-width, initial-scale=1.0,viewport-fit=cover"><title>uni-app | 学习笔记</title><meta name="author" content="lzoxun"><meta name="copyright" content="lzoxun"><meta name="format-detection" content="telephone=no"><meta name="theme-color" content="#ffffff"><meta name="description" content="uni-app基于vue和微信小程序, 一套代码可以发布到ios、Android、h5、以及各种小程序平台  开启uniapp原生开发方式ios  -&gt;  采用ObjectC、Swift语言安卓 -&gt;  Java、Kotlin语言如果企业主要业务在app上，需要更好的用户体验，很多调用硬件api功能，且不惜成本与时间，就可以用原生来开发如果需求只是查找或者是浏览比较基础的功能，就可以">
<meta property="og:type" content="article">
<meta property="og:title" content="uni-app">
<meta property="og:url" content="http://example.com/2023/07/22/web/web-app-uniapp/index.html">
<meta property="og:site_name" content="学习笔记">
<meta property="og:description" content="uni-app基于vue和微信小程序, 一套代码可以发布到ios、Android、h5、以及各种小程序平台  开启uniapp原生开发方式ios  -&gt;  采用ObjectC、Swift语言安卓 -&gt;  Java、Kotlin语言如果企业主要业务在app上，需要更好的用户体验，很多调用硬件api功能，且不惜成本与时间，就可以用原生来开发如果需求只是查找或者是浏览比较基础的功能，就可以">
<meta property="og:locale" content="zh_CN">
<meta property="og:image" content="https://i.loli.net/2021/02/24/5O1day2nriDzjSu.png">
<meta property="article:published_time" content="2023-07-22T07:14:09.697Z">
<meta property="article:modified_time" content="2023-07-22T07:14:09.697Z">
<meta property="article:author" content="lzoxun">
<meta name="twitter:card" content="summary">
<meta name="twitter:image" content="https://i.loli.net/2021/02/24/5O1day2nriDzjSu.png"><link rel="shortcut icon" href="/img/favicon.png"><link rel="canonical" href="http://example.com/2023/07/22/web/web-app-uniapp/index.html"><link rel="preconnect" href="//cdn.jsdelivr.net"/><link rel="preconnect" href="//busuanzi.ibruce.info"/><link rel="stylesheet" href="/css/index.css"><link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/@fortawesome/fontawesome-free/css/all.min.css" media="print" onload="this.media='all'"><link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/node-snackbar/dist/snackbar.min.css" media="print" onload="this.media='all'"><link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/@fancyapps/ui/dist/fancybox/fancybox.min.css" media="print" onload="this.media='all'"><script>const GLOBAL_CONFIG = {
  root: '/',
  algolia: undefined,
  localSearch: {"path":"/search.xml","preload":true,"top_n_per_article":1,"unescape":true,"languages":{"hits_empty":"找不到您查询的内容：${query}","hits_stats":"共找到 ${hits} 篇文章"}},
  translate: {"defaultEncoding":2,"translateDelay":0,"msgToTraditionalChinese":"繁","msgToSimplifiedChinese":"簡"},
  noticeOutdate: undefined,
  highlight: {"plugin":"highlighjs","highlightCopy":true,"highlightLang":true,"highlightHeightLimit":false},
  copy: {
    success: '复制成功',
    error: '复制错误',
    noSupport: '浏览器不支持'
  },
  relativeDate: {
    homepage: false,
    post: false
  },
  runtime: '',
  dateSuffix: {
    just: '刚刚',
    min: '分钟前',
    hour: '小时前',
    day: '天前',
    month: '个月前'
  },
  copyright: undefined,
  lightbox: 'fancybox',
  Snackbar: {"chs_to_cht":"你已切换为繁体","cht_to_chs":"你已切换为简体","day_to_night":"你已切换为深色模式","night_to_day":"你已切换为浅色模式","bgLight":"#49b1f5","bgDark":"#1f1f1f","position":"bottom-left"},
  source: {
    justifiedGallery: {
      js: 'https://cdn.jsdelivr.net/npm/flickr-justified-gallery/dist/fjGallery.min.js',
      css: 'https://cdn.jsdelivr.net/npm/flickr-justified-gallery/dist/fjGallery.min.css'
    }
  },
  isPhotoFigcaption: false,
  islazyload: true,
  isAnchor: false,
  percent: {
    toc: true,
    rightside: false,
  },
  autoDarkmode: false
}</script><script id="config-diff">var GLOBAL_CONFIG_SITE = {
  title: 'uni-app',
  isPost: true,
  isHome: false,
  isHighlightShrink: false,
  isToc: true,
  postUpdate: '2023-07-22 15:14:09'
}</script><noscript><style type="text/css">
  #nav {
    opacity: 1
  }
  .justified-gallery img {
    opacity: 1
  }

  #recent-posts time,
  #post-meta time {
    display: inline !important
  }
</style></noscript><script>(win=>{
    win.saveToLocal = {
      set: function setWithExpiry(key, value, ttl) {
        if (ttl === 0) return
        const now = new Date()
        const expiryDay = ttl * 86400000
        const item = {
          value: value,
          expiry: now.getTime() + expiryDay,
        }
        localStorage.setItem(key, JSON.stringify(item))
      },

      get: function getWithExpiry(key) {
        const itemStr = localStorage.getItem(key)

        if (!itemStr) {
          return undefined
        }
        const item = JSON.parse(itemStr)
        const now = new Date()

        if (now.getTime() > item.expiry) {
          localStorage.removeItem(key)
          return undefined
        }
        return item.value
      }
    }
  
    win.getScript = url => new Promise((resolve, reject) => {
      const script = document.createElement('script')
      script.src = url
      script.async = true
      script.onerror = reject
      script.onload = script.onreadystatechange = function() {
        const loadState = this.readyState
        if (loadState && loadState !== 'loaded' && loadState !== 'complete') return
        script.onload = script.onreadystatechange = null
        resolve()
      }
      document.head.appendChild(script)
    })
  
    win.getCSS = (url,id = false) => new Promise((resolve, reject) => {
      const link = document.createElement('link')
      link.rel = 'stylesheet'
      link.href = url
      if (id) link.id = id
      link.onerror = reject
      link.onload = link.onreadystatechange = function() {
        const loadState = this.readyState
        if (loadState && loadState !== 'loaded' && loadState !== 'complete') return
        link.onload = link.onreadystatechange = null
        resolve()
      }
      document.head.appendChild(link)
    })
  
      win.activateDarkMode = function () {
        document.documentElement.setAttribute('data-theme', 'dark')
        if (document.querySelector('meta[name="theme-color"]') !== null) {
          document.querySelector('meta[name="theme-color"]').setAttribute('content', '#0d0d0d')
        }
      }
      win.activateLightMode = function () {
        document.documentElement.setAttribute('data-theme', 'light')
        if (document.querySelector('meta[name="theme-color"]') !== null) {
          document.querySelector('meta[name="theme-color"]').setAttribute('content', '#ffffff')
        }
      }
      const t = saveToLocal.get('theme')
    
          const now = new Date()
          const hour = now.getHours()
          const isNight = hour <= 6 || hour >= 18
          if (t === undefined) isNight ? activateDarkMode() : activateLightMode()
          else if (t === 'light') activateLightMode()
          else activateDarkMode()
        
      const asideStatus = saveToLocal.get('aside-status')
      if (asideStatus !== undefined) {
        if (asideStatus === 'hide') {
          document.documentElement.classList.add('hide-aside')
        } else {
          document.documentElement.classList.remove('hide-aside')
        }
      }
    
    const detectApple = () => {
      if(/iPad|iPhone|iPod|Macintosh/.test(navigator.userAgent)){
        document.documentElement.classList.add('apple')
      }
    }
    detectApple()
    })(window)</script><meta name="generator" content="Hexo 6.3.0"></head><body><div id="loading-box"><div class="loading-left-bg"></div><div class="loading-right-bg"></div><div class="spinner-box"><div class="configure-border-1"><div class="configure-core"></div></div><div class="configure-border-2"><div class="configure-core"></div></div><div class="loading-word">加载中...</div></div></div><script>(()=>{
  const $loadingBox = document.getElementById('loading-box')
  const $body = document.body
  const preloader = {
    endLoading: () => {
      $body.style.overflow = ''
      $loadingBox.classList.add('loaded')
    },
    initLoading: () => {
      $body.style.overflow = 'hidden'
      $loadingBox.classList.remove('loaded')
    }
  }

  preloader.initLoading()
  window.addEventListener('load',() => { preloader.endLoading() })

  if (false) {
    document.addEventListener('pjax:send', () => { preloader.initLoading() })
    document.addEventListener('pjax:complete', () => { preloader.endLoading() })
  }
})()</script><div id="sidebar"><div id="menu-mask"></div><div id="sidebar-menus"><div class="avatar-img is-center"><img src= "" data-lazy-src="https://i.loli.net/2021/02/24/5O1day2nriDzjSu.png" onerror="onerror=null;src='/img/friend_404.gif'" alt="avatar"/></div><div class="sidebar-site-data site-data is-center"><a href="/archives/"><div class="headline">文章</div><div class="length-num">108</div></a><a href="/tags/"><div class="headline">标签</div><div class="length-num">1</div></a><a href="/categories/"><div class="headline">分类</div><div class="length-num">0</div></a></div><hr class="custom-hr"/><div class="menus_items"><div class="menus_item"><a class="site-page" href="/"><i class="fa-fw fas fa-home"></i><span> 首页</span></a></div><div class="menus_item"><a class="site-page" href="/archives/"><i class="fa-fw fas fa-archive"></i><span> 归档</span></a></div><div class="menus_item"><a class="site-page" href="/tags/"><i class="fa-fw fas fa-tags"></i><span> 标签</span></a></div></div></div></div><div class="post" id="body-wrap"><header class="post-bg" id="page-header"><nav id="nav"><span id="blog-info"><a href="/" title="学习笔记"><span class="site-name">学习笔记</span></a></span><div id="menus"><div id="search-button"><a class="site-page social-icon search" href="javascript:void(0);"><i class="fas fa-search fa-fw"></i><span> 搜索</span></a></div><div class="menus_items"><div class="menus_item"><a class="site-page" href="/"><i class="fa-fw fas fa-home"></i><span> 首页</span></a></div><div class="menus_item"><a class="site-page" href="/archives/"><i class="fa-fw fas fa-archive"></i><span> 归档</span></a></div><div class="menus_item"><a class="site-page" href="/tags/"><i class="fa-fw fas fa-tags"></i><span> 标签</span></a></div></div><div id="toggle-menu"><a class="site-page" href="javascript:void(0);"><i class="fas fa-bars fa-fw"></i></a></div></div></nav><div id="post-info"><h1 class="post-title">uni-app</h1><div id="post-meta"><div class="meta-firstline"><span class="post-meta-date"><i class="far fa-calendar-alt fa-fw post-meta-icon"></i><span class="post-meta-label">发表于</span><time class="post-meta-date-created" datetime="2023-07-22T07:14:09.697Z" title="发表于 2023-07-22 15:14:09">2023-07-22</time><span class="post-meta-separator">|</span><i class="fas fa-history fa-fw post-meta-icon"></i><span class="post-meta-label">更新于</span><time class="post-meta-date-updated" datetime="2023-07-22T07:14:09.697Z" title="更新于 2023-07-22 15:14:09">2023-07-22</time></span></div><div class="meta-secondline"><span class="post-meta-separator">|</span><span class="post-meta-pv-cv" id="" data-flag-title="uni-app"><i class="far fa-eye fa-fw post-meta-icon"></i><span class="post-meta-label">阅读量:</span><span id="busuanzi_value_page_pv"><i class="fa-solid fa-spinner fa-spin"></i></span></span></div></div></div></header><main class="layout" id="content-inner"><div id="post"><article class="post-content" id="article-container"><blockquote>
<p>uni-app基于vue和微信小程序, 一套代码可以发布到ios、Android、h5、以及各种小程序平台</p>
</blockquote>
<h2 id="开启uniapp"><a href="#开启uniapp" class="headerlink" title="开启uniapp"></a>开启uniapp</h2><p>原生开发方式<br>ios  -&gt;  采用ObjectC、Swift语言<br>安卓 -&gt;  Java、Kotlin语言<br>如果企业主要业务在app上，需要更好的用户体验，很多调用硬件api功能，且不惜成本与时间，就可以用原生来开发<br>如果需求只是查找或者是浏览比较基础的功能，就可以用web paa 混合开发</p>
<p>对比uniapp优点<br>1、官方指定方案更受认可<br>2、性能以及用户体验更好<br>3、可以直接调用硬件能力<br>缺点<br>1、开发成本高<br>2、开发周期长<br>3、ios与安卓需要分开开发与维护</p>
<p>常见跨端开发方式<br>Vue技术栈（Uniapp、Weex）<br>React技术栈（ReactNative、Taro）<br>Flutter 这个需要Dart语言，不是通过js开发的</p>
<h3 id="环境搭建"><a href="#环境搭建" class="headerlink" title="环境搭建"></a>环境搭建</h3><blockquote>
<p>安装编辑器HbuilderX <a target="_blank" rel="noopener" href="https://uniapp.dcloud.io/">官网</a></p>
</blockquote>
<h3 id="运行"><a href="#运行" class="headerlink" title="运行"></a>运行</h3><p>运行到小程序d -&gt; 微信开发者工具第一次要配置安装目录,百度等也要先配置好开发者工具安装目录<br>配置好后，开发这者工具设置-&gt;安全-&gt;端口打开才能打开</p>
<p>运行到手机需要连接数据线</p>
<h3 id="规范"><a href="#规范" class="headerlink" title="规范"></a>规范</h3><p>页面规范一般遵守vue单文件组件格式<br>标签靠近小程序规范<br><a target="_blank" rel="noopener" href="https://developers.weixin.qq.com/miniprogram/dev/api/base/wx.canIUse.html">小程序文档</a></p>
<h3 id="条件注释跨端兼容"><a href="#条件注释跨端兼容" class="headerlink" title="条件注释跨端兼容"></a>条件注释跨端兼容</h3><p><a target="_blank" rel="noopener" href="https://uniapp.dcloud.io/platform?id=%E6%9D%A1%E4%BB%B6%E7%BC%96%E8%AF%91">条件编译</a></p>
<figure class="highlight javascript"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br></pre></td><td class="code"><pre><span class="line">#ifndef <span class="variable constant_">H5</span></span><br><span class="line">需条件编译的代码</span><br><span class="line">#endif</span><br></pre></td></tr></table></figure>
<h2 id="目录结构与项目配置"><a href="#目录结构与项目配置" class="headerlink" title="目录结构与项目配置"></a>目录结构与项目配置</h2><h3 id="目录结构"><a href="#目录结构" class="headerlink" title="目录结构"></a>目录结构</h3><figure class="highlight python"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br></pre></td><td class="code"><pre><span class="line">pages  <span class="comment">#存放所有页面</span></span><br><span class="line">static  <span class="comment">#存放静态文件</span></span><br><span class="line">unpackage  <span class="comment">#打包h5、安卓打包成功后的文件存放位置</span></span><br><span class="line">App.vue  <span class="comment">#整个项目跟组件，所有页面都是在这里进行切换(生命周期在此设置)</span></span><br><span class="line">main.js <span class="comment">#项目的入了文件， 加载时首先走这个文件</span></span><br><span class="line">manifest.json <span class="comment">#配置各种打包方式的配置文件</span></span><br><span class="line">pages.json <span class="comment">#存放整个项目的页面路径与窗口外观</span></span><br><span class="line">uni.scss <span class="comment">#常用的样式全局变量</span></span><br></pre></td></tr></table></figure>

<h3 id="全局配置"><a href="#全局配置" class="headerlink" title="全局配置"></a>全局配置</h3><p><a target="_blank" rel="noopener" href="https://developers.weixin.qq.com/miniprogram/dev/reference/configuration/app.html">小程序基础配置</a><br><a target="_blank" rel="noopener" href="https://uniapp.dcloud.io/collocation/pages">uniapp配置文档</a></p>
<figure class="highlight json"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br><span class="line">23</span><br><span class="line">24</span><br><span class="line">25</span><br><span class="line">26</span><br><span class="line">27</span><br><span class="line">28</span><br><span class="line">29</span><br><span class="line">30</span><br><span class="line">31</span><br><span class="line">32</span><br><span class="line">33</span><br><span class="line">34</span><br><span class="line">35</span><br><span class="line">36</span><br><span class="line">37</span><br><span class="line">38</span><br><span class="line">39</span><br><span class="line">40</span><br><span class="line">41</span><br><span class="line">42</span><br><span class="line">43</span><br><span class="line">44</span><br><span class="line">45</span><br><span class="line">46</span><br><span class="line">47</span><br><span class="line">48</span><br><span class="line">49</span><br><span class="line">50</span><br><span class="line">51</span><br><span class="line">52</span><br><span class="line">53</span><br><span class="line">54</span><br><span class="line">55</span><br><span class="line">56</span><br><span class="line">57</span><br><span class="line">58</span><br><span class="line">59</span><br><span class="line">60</span><br><span class="line">61</span><br><span class="line">62</span><br><span class="line">63</span><br><span class="line">64</span><br><span class="line">65</span><br><span class="line">66</span><br><span class="line">67</span><br><span class="line">68</span><br><span class="line">69</span><br><span class="line">70</span><br></pre></td><td class="code"><pre><span class="line"><span class="comment">//pages.json</span></span><br><span class="line"><span class="punctuation">&#123;</span></span><br><span class="line">	<span class="attr">&quot;pages&quot;</span><span class="punctuation">:</span> <span class="punctuation">[</span> <span class="comment">//=========================pages数组中第一项表示应用启动页</span></span><br><span class="line">		<span class="punctuation">&#123;</span></span><br><span class="line">			<span class="attr">&quot;path&quot;</span><span class="punctuation">:</span> <span class="string">&quot;pages/index/index&quot;</span><span class="punctuation">,</span></span><br><span class="line">			<span class="attr">&quot;style&quot;</span><span class="punctuation">:</span> <span class="punctuation">&#123;</span> <span class="comment">//设置页面独有外观样式，属性与全局一样</span></span><br><span class="line">                <span class="attr">&quot;navigationBarTitleText&quot;</span><span class="punctuation">:</span> <span class="string">&quot;uni-app全局首页&quot;</span><span class="punctuation">,</span></span><br><span class="line">                <span class="attr">&quot;enablePullDownRefresh&quot;</span><span class="punctuation">:</span><span class="literal"><span class="keyword">true</span></span><span class="punctuation">,</span> <span class="comment">//设置下拉刷新 uni.stopPullDownRefresh()手动关闭</span></span><br><span class="line">                <span class="attr">&quot;onReachBottomDistance&quot;</span><span class="punctuation">:</span><span class="string">&quot;50px&quot;</span><span class="punctuation">,</span> <span class="comment">//设置距离底部多少触发上拉刷新函数</span></span><br><span class="line">                <span class="attr">&quot;h5&quot;</span><span class="punctuation">:</span><span class="punctuation">&#123;</span></span><br><span class="line">					<span class="attr">&quot;titleNView&quot;</span><span class="punctuation">:</span><span class="punctuation">&#123;</span></span><br><span class="line">						<span class="attr">&quot;titleText&quot;</span><span class="punctuation">:</span><span class="string">&quot;h5首页标题&quot;</span></span><br><span class="line">					<span class="punctuation">&#125;</span></span><br><span class="line">                <span class="punctuation">&#125;</span></span><br><span class="line">			<span class="punctuation">&#125;</span></span><br><span class="line">		<span class="punctuation">&#125;</span><span class="punctuation">,</span></span><br><span class="line">		<span class="punctuation">&#123;</span></span><br><span class="line">			<span class="attr">&quot;path&quot;</span><span class="punctuation">:</span> <span class="string">&quot;pages/about/new_file&quot;</span><span class="punctuation">,</span></span><br><span class="line">			<span class="attr">&quot;style&quot;</span><span class="punctuation">:</span> <span class="punctuation">&#123;</span></span><br><span class="line">		        <span class="attr">&quot;navigationBarTitleText&quot;</span><span class="punctuation">:</span> <span class="string">&quot;uni-app全局关于页面&quot;</span><span class="punctuation">,</span></span><br><span class="line">		        <span class="attr">&quot;h5&quot;</span><span class="punctuation">:</span><span class="punctuation">&#123;</span></span><br><span class="line">					<span class="attr">&quot;titleNView&quot;</span><span class="punctuation">:</span><span class="punctuation">&#123;</span></span><br><span class="line">						<span class="attr">&quot;titleText&quot;</span><span class="punctuation">:</span><span class="string">&quot;h5关于页面&quot;</span></span><br><span class="line">					<span class="punctuation">&#125;</span></span><br><span class="line">		        <span class="punctuation">&#125;</span></span><br><span class="line">			<span class="punctuation">&#125;</span></span><br><span class="line">		<span class="punctuation">&#125;</span></span><br><span class="line">	<span class="punctuation">]</span><span class="punctuation">,</span></span><br><span class="line">	</span><br><span class="line">	<span class="attr">&quot;globalStyle&quot;</span><span class="punctuation">:</span> <span class="punctuation">&#123;</span> <span class="comment">//===============================配置程序全局所有页面样式</span></span><br><span class="line">		<span class="attr">&quot;navigationBarTextStyle&quot;</span><span class="punctuation">:</span> <span class="string">&quot;black&quot;</span><span class="punctuation">,</span></span><br><span class="line">		<span class="attr">&quot;navigationBarTitleText&quot;</span><span class="punctuation">:</span> <span class="string">&quot;uni-app&quot;</span><span class="punctuation">,</span></span><br><span class="line">		<span class="attr">&quot;navigationBarBackgroundColor&quot;</span><span class="punctuation">:</span> <span class="string">&quot;#F8F8F8&quot;</span><span class="punctuation">,</span></span><br><span class="line">        <span class="attr">&quot;backgroundColor&quot;</span><span class="punctuation">:</span> <span class="string">&quot;#F8F8F8&quot;</span><span class="punctuation">,</span></span><br><span class="line">        <span class="attr">&quot;enablePullDownRefresh&quot;</span><span class="punctuation">:</span><span class="literal"><span class="keyword">true</span></span> <span class="comment">//下拉刷新</span></span><br><span class="line">	<span class="punctuation">&#125;</span><span class="punctuation">,</span></span><br><span class="line">	</span><br><span class="line">	<span class="attr">&quot;tabBar&quot;</span><span class="punctuation">:</span> <span class="punctuation">&#123;</span> <span class="comment">// ===================================配置底部菜单</span></span><br><span class="line">	    <span class="attr">&quot;color&quot;</span><span class="punctuation">:</span> <span class="string">&quot;#7A7E83&quot;</span><span class="punctuation">,</span>  <span class="comment">//颜色</span></span><br><span class="line">	    <span class="attr">&quot;selectedColor&quot;</span><span class="punctuation">:</span> <span class="string">&quot;#3cc51f&quot;</span><span class="punctuation">,</span>  <span class="comment">//选中的颜色</span></span><br><span class="line">	    <span class="attr">&quot;borderStyle&quot;</span><span class="punctuation">:</span> <span class="string">&quot;black&quot;</span><span class="punctuation">,</span></span><br><span class="line">	    <span class="attr">&quot;backgroundColor&quot;</span><span class="punctuation">:</span> <span class="string">&quot;#ffffff&quot;</span><span class="punctuation">,</span></span><br><span class="line">		<span class="attr">&quot;position&quot;</span><span class="punctuation">:</span><span class="string">&quot;top&quot;</span><span class="punctuation">,</span> <span class="comment">//仅微信小程序支持</span></span><br><span class="line">	    <span class="attr">&quot;list&quot;</span><span class="punctuation">:</span> <span class="punctuation">[</span><span class="punctuation">&#123;</span></span><br><span class="line">	        <span class="attr">&quot;pagePath&quot;</span><span class="punctuation">:</span> <span class="string">&quot;pages/index/index&quot;</span><span class="punctuation">,</span></span><br><span class="line">	        <span class="attr">&quot;iconPath&quot;</span><span class="punctuation">:</span> <span class="string">&quot;static/logo.png&quot;</span><span class="punctuation">,</span> <span class="comment">//图标路径</span></span><br><span class="line">	        <span class="attr">&quot;selectedIconPath&quot;</span><span class="punctuation">:</span> <span class="string">&quot;static/logo.png&quot;</span><span class="punctuation">,</span> <span class="comment">//选中的图标路径</span></span><br><span class="line">	        <span class="attr">&quot;text&quot;</span><span class="punctuation">:</span> <span class="string">&quot;首页&quot;</span></span><br><span class="line">	    <span class="punctuation">&#125;</span><span class="punctuation">,</span> <span class="punctuation">&#123;</span></span><br><span class="line">	        <span class="attr">&quot;pagePath&quot;</span><span class="punctuation">:</span> <span class="string">&quot;pages/about/new_file&quot;</span><span class="punctuation">,</span></span><br><span class="line">	        <span class="attr">&quot;iconPath&quot;</span><span class="punctuation">:</span> <span class="string">&quot;static/logo.png&quot;</span><span class="punctuation">,</span></span><br><span class="line">	        <span class="attr">&quot;selectedIconPath&quot;</span><span class="punctuation">:</span> <span class="string">&quot;static/logo.png&quot;</span><span class="punctuation">,</span></span><br><span class="line">	        <span class="attr">&quot;text&quot;</span><span class="punctuation">:</span> <span class="string">&quot;关于&quot;</span></span><br><span class="line">	    <span class="punctuation">&#125;</span><span class="punctuation">]</span></span><br><span class="line">	<span class="punctuation">&#125;</span><span class="punctuation">,</span></span><br><span class="line">	</span><br><span class="line">	<span class="attr">&quot;condition&quot;</span><span class="punctuation">:</span> <span class="punctuation">&#123;</span> <span class="comment">//=== 模式配置，仅开发期间生效，开发的时候直接切换开发者工具编译模式到某个页面进行开发</span></span><br><span class="line">	    <span class="attr">&quot;current&quot;</span><span class="punctuation">:</span> <span class="number">0</span><span class="punctuation">,</span> <span class="comment">//当前激活的模式（list 的索引项）</span></span><br><span class="line">	    <span class="attr">&quot;list&quot;</span><span class="punctuation">:</span> <span class="punctuation">[</span><span class="punctuation">&#123;</span></span><br><span class="line">	            <span class="attr">&quot;name&quot;</span><span class="punctuation">:</span> <span class="string">&quot;swiper&quot;</span><span class="punctuation">,</span> <span class="comment">//模式名称</span></span><br><span class="line">	            <span class="attr">&quot;path&quot;</span><span class="punctuation">:</span> <span class="string">&quot;pages/about/new_file&quot;</span><span class="punctuation">,</span> <span class="comment">//启动页面，必选</span></span><br><span class="line">	            <span class="attr">&quot;query&quot;</span><span class="punctuation">:</span> <span class="string">&quot;interval=4000&amp;autoplay=false&quot;</span> <span class="comment">//启动参数，在页面的onLoad函数里面得到。</span></span><br><span class="line">	        <span class="punctuation">&#125;</span><span class="punctuation">,</span></span><br><span class="line">	        <span class="punctuation">&#123;</span></span><br><span class="line">	            <span class="attr">&quot;name&quot;</span><span class="punctuation">:</span> <span class="string">&quot;test&quot;</span><span class="punctuation">,</span></span><br><span class="line">	            <span class="attr">&quot;path&quot;</span><span class="punctuation">:</span> <span class="string">&quot;pages/index/index&quot;</span></span><br><span class="line">	        <span class="punctuation">&#125;</span></span><br><span class="line">	    <span class="punctuation">]</span></span><br><span class="line">	<span class="punctuation">&#125;</span></span><br><span class="line"><span class="punctuation">&#125;</span></span><br></pre></td></tr></table></figure>

<h3 id="组件"><a href="#组件" class="headerlink" title="组件"></a>组件</h3><p><a target="_blank" rel="noopener" href="https://uniapp.dcloud.io/component/README">uniapp组件</a></p>
<h4 id="内置组件"><a href="#内置组件" class="headerlink" title="内置组件"></a>内置组件</h4><figure class="highlight html"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br></pre></td><td class="code"><pre><span class="line">代替HTML标签,并加了很多参数属性</span><br><span class="line"><span class="tag">&lt;<span class="name">view</span>&gt;</span></span><br><span class="line"><span class="tag">&lt;<span class="name">text</span>&gt;</span></span><br><span class="line"><span class="tag">&lt;<span class="name">button</span>&gt;</span></span><br><span class="line"><span class="tag">&lt;<span class="name">image</span>&gt;</span> </span><br><span class="line">...</span><br><span class="line"></span><br><span class="line"><span class="comment">&lt;!--view新属性--&gt;</span></span><br><span class="line">hover-class=&#x27;鼠标按下的类&#x27;</span><br><span class="line">hover-stop-propagation  属性阻止事件冒泡</span><br><span class="line">hover-start-time  多久延迟出现hover类效果</span><br><span class="line">hover-stay-time 离开后保持多久失去效果</span><br><span class="line">...</span><br></pre></td></tr></table></figure>

<h4 id="创建组件"><a href="#创建组件" class="headerlink" title="创建组件"></a>创建组件</h4><blockquote>
<p>创建 ：后缀名.vue文件，视为一个组件<br>使用 ：通过import 组件名 from “xxx”导入并通过components注册,完成之后通过标签形式使用</p>
</blockquote>
<h5 id="组件通讯"><a href="#组件通讯" class="headerlink" title="组件通讯"></a>组件通讯</h5><p><a target="_blank" rel="noopener" href="https://uniapp.dcloud.io/collocation/frame/communication">组件通讯</a></p>
<blockquote>
<p>父传子 : 以标签形式调用组件是 :data 传到子组件, 组件中:prop[‘data’] 接收<br>子传父 : this.$emit(‘父级自定义方法 par’)， 父组件中: @par &#x3D; ‘xxx’  </p>
</blockquote>
<p>兄弟组件传值 : </p>
<figure class="highlight javascript"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br></pre></td><td class="code"><pre><span class="line"><span class="comment">//组件A</span></span><br><span class="line"><span class="comment">//触发全局的update函数 将父子间的this换成uni</span></span><br><span class="line">uni.$emit(<span class="string">&#x27;update&#x27;</span>,&#123;<span class="attr">msg</span>:<span class="string">&#x27;页面更新&#x27;</span>&#125;)</span><br><span class="line"></span><br><span class="line"><span class="comment">//组件B</span></span><br><span class="line"><span class="comment">//监听全局的自定义事件update</span></span><br><span class="line">uni.$on(<span class="string">&#x27;update&#x27;</span>,<span class="keyword">function</span>(<span class="params">data</span>)&#123;</span><br><span class="line">	<span class="variable language_">console</span>.<span class="title function_">log</span>(<span class="string">&#x27;监听到事件来自 update ，携带参数 msg 为：&#x27;</span> + data.<span class="property">msg</span>);</span><br><span class="line">&#125;)</span><br></pre></td></tr></table></figure>

<h3 id="uniapp中的样式"><a href="#uniapp中的样式" class="headerlink" title="uniapp中的样式"></a>uniapp中的样式</h3><p>不同点</p>
<ul>
<li>rpx<br>响应式px,类似rem,根据屏幕宽度自适应的单位,以750为基准,750rex恰好为屏幕宽度,屏幕变宽,1rpx实际显示效果等比放大<br>750rpx相当于100%</li>
<li>style标签中 @import url(“xxxx”) 导入样式表</li>
<li>不能使用 * 选择器</li>
<li>page详单与body</li>
<li>App.vue的样式为全局样式,pages下页面的样式为局部样式,覆盖全局样式 </li>
<li>字体图标注意事项<ul>
<li>字体文件大小不能超过4kb,否则要自己手动转base64</li>
<li>引用的时候建议使用 ~@static&#x2F;fonts&#x2F;xxx 开头的绝对路径引入字体</li>
<li>字体图标放在static目录下,在App.vue中全局引入css,</li>
</ul>
</li>
<li>直接 lang&#x3D;”scss” 并且安装sass插件就能使用sass了,sass才能使用uni.scss里的变量</li>
</ul>
<h3 id="数据绑定事件…"><a href="#数据绑定事件…" class="headerlink" title="数据绑定事件…"></a>数据绑定事件…</h3><p>与vue一样</p>
<h3 id="uni生命周期"><a href="#uni生命周期" class="headerlink" title="uni生命周期"></a>uni生命周期</h3><blockquote>
<p>生命周期概念: 一个对象被创建、运行、销毁的这个过程<br>生命周期函数:生命周期每个阶段都会有相应生命周期函数自动触发</p>
</blockquote>
<p><a target="_blank" rel="noopener" href="https://uniapp.dcloud.io/collocation/frame/lifecycle">生命周期</a></p>
<h4 id="应用的生命周期"><a href="#应用的生命周期" class="headerlink" title="应用的生命周期"></a>应用的生命周期</h4><figure class="highlight javascript"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br><span class="line">23</span><br><span class="line">24</span><br></pre></td><td class="code"><pre><span class="line"><span class="comment">//App.vue</span></span><br><span class="line">&lt;script&gt;</span><br><span class="line">	<span class="keyword">export</span> <span class="keyword">default</span> &#123;</span><br><span class="line">		<span class="comment">//应用的生命周期</span></span><br><span class="line">		<span class="attr">onLaunch</span>: <span class="keyword">function</span>(<span class="params"></span>) &#123; <span class="comment">//uniapp初始化完成触发(全程只触发一次)</span></span><br><span class="line">			<span class="variable language_">console</span>.<span class="title function_">log</span>(<span class="string">&#x27;App Launch&#x27;</span>)</span><br><span class="line">		&#125;,</span><br><span class="line">		<span class="attr">onShow</span>: <span class="keyword">function</span>(<span class="params"></span>) &#123; <span class="comment">//uniapp启动,或从后台到前台触发</span></span><br><span class="line">			<span class="variable language_">console</span>.<span class="title function_">log</span>(<span class="string">&#x27;App Show&#x27;</span>)</span><br><span class="line">		&#125;,</span><br><span class="line">		<span class="attr">onHide</span>: <span class="keyword">function</span>(<span class="params"></span>) &#123; <span class="comment">//uniapp从前台到后台触发</span></span><br><span class="line">			<span class="variable language_">console</span>.<span class="title function_">log</span>(<span class="string">&#x27;App Hide&#x27;</span>)</span><br><span class="line">		&#125;,</span><br><span class="line">		<span class="attr">onError</span>: <span class="keyword">function</span>(<span class="params"></span>) &#123; <span class="comment">//uniapp 报错触发</span></span><br><span class="line">			<span class="variable language_">console</span>.<span class="title function_">log</span>(<span class="string">&#x27;App Error&#x27;</span>)</span><br><span class="line">        &#125;</span><br><span class="line">        ...</span><br><span class="line">	&#125;</span><br><span class="line">&lt;/script&gt;</span><br><span class="line"></span><br><span class="line"><span class="language-xml"><span class="tag">&lt;<span class="name">style</span>&gt;</span><span class="language-css"></span></span></span><br><span class="line"><span class="language-css"><span class="language-xml">	<span class="comment">/*每个页面公共css */</span></span></span></span><br><span class="line"><span class="language-css"><span class="language-xml"></span><span class="tag">&lt;/<span class="name">style</span>&gt;</span></span></span><br><span class="line"></span><br></pre></td></tr></table></figure>

<h4 id="页面的生命周期"><a href="#页面的生命周期" class="headerlink" title="页面的生命周期"></a>页面的生命周期</h4><figure class="highlight javascript"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br><span class="line">23</span><br><span class="line">24</span><br><span class="line">25</span><br><span class="line">26</span><br><span class="line">27</span><br><span class="line">28</span><br><span class="line">29</span><br><span class="line">30</span><br><span class="line">31</span><br><span class="line">32</span><br><span class="line">33</span><br><span class="line">34</span><br><span class="line">35</span><br><span class="line">36</span><br><span class="line">37</span><br></pre></td><td class="code"><pre><span class="line"><span class="comment">//普通页面中</span></span><br><span class="line">&lt;script&gt;</span><br><span class="line">	<span class="keyword">export</span> <span class="keyword">default</span> &#123;</span><br><span class="line">		<span class="title function_">data</span>(<span class="params"></span>) &#123;</span><br><span class="line">			<span class="keyword">return</span> &#123;</span><br><span class="line">				<span class="attr">title</span>: <span class="string">&#x27;Hello&#x27;</span></span><br><span class="line">			&#125;</span><br><span class="line">		&#125;,</span><br><span class="line">		<span class="title function_">onLoad</span>(<span class="params">option</span>) &#123;</span><br><span class="line">			<span class="comment">//监听页面加载 ，并拿到上级页面传递的参数</span></span><br><span class="line">			<span class="comment">//只会触发一次页面切换时不会触发</span></span><br><span class="line">			<span class="variable language_">console</span>.<span class="title function_">log</span>(<span class="string">&quot;页面加载了&quot;</span>+ option)</span><br><span class="line">		&#125;,</span><br><span class="line">		<span class="title function_">onShow</span>(<span class="params"></span>) &#123; <span class="comment">//监听页面显示</span></span><br><span class="line">			<span class="variable language_">console</span>.<span class="title function_">log</span>(<span class="string">&quot;页面出现在屏幕上了&quot;</span>)</span><br><span class="line">		&#125;,</span><br><span class="line">		<span class="title function_">onReady</span>(<span class="params"></span>) &#123; <span class="comment">//监听页面初次渲染完成 </span></span><br><span class="line">			<span class="variable language_">console</span>.<span class="title function_">log</span>(<span class="string">&quot;监听页面初次渲染完成 &quot;</span>)</span><br><span class="line">		&#125;,</span><br><span class="line">		<span class="title function_">onHide</span>(<span class="params"></span>) &#123; <span class="comment">//监听页面隐藏</span></span><br><span class="line">			<span class="variable language_">console</span>.<span class="title function_">log</span>(<span class="string">&quot;页面隐藏&quot;</span>)</span><br><span class="line">		&#125;,</span><br><span class="line">		<span class="title function_">onUnload</span>(<span class="params"></span>) &#123; <span class="comment">//讲台页面卸载</span></span><br><span class="line">			<span class="variable language_">console</span>.<span class="title function_">log</span>(<span class="string">&quot;页面卸载&quot;</span>)</span><br><span class="line">        &#125;,</span><br><span class="line">        <span class="title function_">onPullDownRefresh</span>(<span class="params"></span>)&#123;</span><br><span class="line">			<span class="variable language_">console</span>.<span class="title function_">log</span>(<span class="string">&quot;用户下拉页面了&quot;</span>)</span><br><span class="line">        &#125;,</span><br><span class="line">        <span class="title function_">onReachBottom</span>(<span class="params"></span>)&#123; <span class="comment">//向下滚动触底时触发</span></span><br><span class="line">			<span class="variable language_">console</span>.<span class="title function_">log</span>(<span class="string">&quot;用户上拉&quot;</span>)</span><br><span class="line">		&#125;,</span><br><span class="line">        ...</span><br><span class="line">		<span class="attr">methods</span>: &#123;</span><br><span class="line"></span><br><span class="line">		&#125;</span><br><span class="line">	&#125;</span><br><span class="line">&lt;/script&gt;</span><br></pre></td></tr></table></figure>

<h4 id="组件的生命周期"><a href="#组件的生命周期" class="headerlink" title="组件的生命周期"></a>组件的生命周期</h4><figure class="highlight javascript"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br><span class="line">23</span><br><span class="line">24</span><br><span class="line">25</span><br><span class="line">26</span><br><span class="line">27</span><br><span class="line">28</span><br><span class="line">29</span><br><span class="line">30</span><br><span class="line">31</span><br></pre></td><td class="code"><pre><span class="line"><span class="comment">//组件中</span></span><br><span class="line">&lt;script&gt;</span><br><span class="line">	<span class="keyword">export</span> <span class="keyword">default</span> &#123;</span><br><span class="line">		<span class="title function_">data</span>(<span class="params"></span>) &#123;</span><br><span class="line">			<span class="keyword">return</span> &#123;</span><br><span class="line">				<span class="attr">title</span>: <span class="string">&#x27;Hello&#x27;</span></span><br><span class="line">			&#125;</span><br><span class="line">		&#125;,</span><br><span class="line">		<span class="title function_">beforeCreate</span>(<span class="params"></span>)&#123;</span><br><span class="line">			<span class="variable language_">console</span>.<span class="title function_">log</span>(<span class="string">&quot;在实例初始化之后 无data数据&quot;</span>)</span><br><span class="line">		&#125;,</span><br><span class="line">		<span class="title function_">created</span>(<span class="params"></span>) &#123;</span><br><span class="line">			<span class="variable language_">console</span>.<span class="title function_">log</span>(<span class="string">&quot;在实例创建完成后 有data数据&quot;</span>)</span><br><span class="line">		&#125;,</span><br><span class="line">		<span class="title function_">beforeMount</span>(<span class="params"></span>)&#123;</span><br><span class="line">			<span class="variable language_">console</span>.<span class="title function_">log</span>(<span class="string">&quot;挂载到实例上去之前调用 无dom节点&quot;</span>)</span><br><span class="line">		&#125;,</span><br><span class="line">		<span class="title function_">mounted</span>(<span class="params"></span>)&#123;</span><br><span class="line">			<span class="variable language_">console</span>.<span class="title function_">log</span>(<span class="string">&quot;挂载到实例上去之后调用  有dom节点&quot;</span>)</span><br><span class="line">		&#125;,</span><br><span class="line">		beforeUpdate </span><br><span class="line">		updated <span class="comment">//数据更新 仅支持h5</span></span><br><span class="line">		beforeDestroy</span><br><span class="line">		destroyed <span class="comment">//组件销毁</span></span><br><span class="line"></span><br><span class="line">		......</span><br><span class="line">		<span class="attr">methods</span>: &#123;</span><br><span class="line"></span><br><span class="line">		&#125;</span><br><span class="line">	&#125;</span><br><span class="line">&lt;/script&gt;</span><br></pre></td></tr></table></figure>

<h2 id="交互"><a href="#交互" class="headerlink" title="交互"></a>交互</h2><h3 id="网络请求"><a href="#网络请求" class="headerlink" title="网络请求"></a>网络请求</h3><p><a target="_blank" rel="noopener" href="https://uniapp.dcloud.io/api/request/request?id=request">uni request</a></p>
<figure class="highlight javascript"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br></pre></td><td class="code"><pre><span class="line">uni.<span class="title function_">request</span>(&#123;</span><br><span class="line">	url</span><br><span class="line">	method</span><br><span class="line">    data</span><br><span class="line">    header</span><br><span class="line">	<span class="attr">success</span>: <span class="function">(<span class="params">res</span>) =&gt;</span> &#123;</span><br><span class="line">		</span><br><span class="line">	&#125;</span><br><span class="line">	...</span><br><span class="line">&#125;);</span><br></pre></td></tr></table></figure>

<h3 id="数据缓存"><a href="#数据缓存" class="headerlink" title="数据缓存"></a>数据缓存</h3><p><a target="_blank" rel="noopener" href="https://uniapp.dcloud.io/api/storage/storage?id=setstorage">文档路径</a></p>
<figure class="highlight javascript"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br><span class="line">19</span><br><span class="line">20</span><br><span class="line">21</span><br><span class="line">22</span><br><span class="line">23</span><br><span class="line">24</span><br><span class="line">25</span><br><span class="line">26</span><br></pre></td><td class="code"><pre><span class="line">uni.<span class="title function_">setStorage</span>(&#123; <span class="comment">//存储数据   设置的是localStorage</span></span><br><span class="line">	<span class="attr">key</span>: <span class="string">&#x27;storage_key&#x27;</span>,</span><br><span class="line">	<span class="attr">data</span>: <span class="string">&#x27;hello&#x27;</span>,</span><br><span class="line">	<span class="attr">success</span>: <span class="keyword">function</span> (<span class="params"></span>) &#123;</span><br><span class="line">		<span class="variable language_">console</span>.<span class="title function_">log</span>(<span class="string">&#x27;设置缓存success&#x27;</span>);</span><br><span class="line">	&#125;</span><br><span class="line">&#125;);</span><br><span class="line"></span><br><span class="line">uni.<span class="title function_">getStorage</span>(&#123; <span class="comment">//获取数据 异步不会阻塞，有时可能获取不到</span></span><br><span class="line">	<span class="attr">key</span>: <span class="string">&#x27;storage_key&#x27;</span>,</span><br><span class="line">	<span class="attr">success</span>: <span class="keyword">function</span> (<span class="params">res</span>) &#123;</span><br><span class="line">		<span class="variable language_">console</span>.<span class="title function_">log</span>(res.<span class="property">data</span>);</span><br><span class="line">	&#125;</span><br><span class="line">&#125;);</span><br><span class="line"></span><br><span class="line">uni.<span class="title function_">removeStorage</span>(&#123; <span class="comment">//删除数据</span></span><br><span class="line">	<span class="attr">key</span>: <span class="string">&#x27;storage_key&#x27;</span>,</span><br><span class="line">	<span class="attr">success</span>: <span class="keyword">function</span> (<span class="params">res</span>) &#123;</span><br><span class="line">		<span class="variable language_">console</span>.<span class="title function_">log</span>(<span class="string">&#x27;删除success&#x27;</span>);</span><br><span class="line">	&#125;</span><br><span class="line">&#125;);</span><br><span class="line"></span><br><span class="line"><span class="comment">//加Sync的同步接口</span></span><br><span class="line"> uni.<span class="title function_">setStorageSync</span>(<span class="string">&#x27;storage_key&#x27;</span>, <span class="string">&#x27;hello&#x27;</span>);</span><br><span class="line"> <span class="keyword">const</span> value = uni.<span class="title function_">getStorageSync</span>(<span class="string">&#x27;storage_key&#x27;</span>); <span class="comment">//同步的一定能获取到</span></span><br><span class="line"> uni.<span class="title function_">removeStorageSync</span>(<span class="string">&#x27;storage_key&#x27;</span>);</span><br></pre></td></tr></table></figure>

<h3 id="图片上传"><a href="#图片上传" class="headerlink" title="图片上传"></a>图片上传</h3><p><a target="_blank" rel="noopener" href="https://uniapp.dcloud.io/api/media/image?id=chooseimage">媒体图片</a></p>
<figure class="highlight javascript"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br></pre></td><td class="code"><pre><span class="line">uni.<span class="title function_">chooseImage</span>(&#123;</span><br><span class="line">	<span class="attr">count</span>: <span class="number">6</span>, </span><br><span class="line">	<span class="attr">success</span>: <span class="keyword">function</span> (<span class="params">res</span>) &#123;</span><br><span class="line">		<span class="variable language_">console</span>.<span class="title function_">log</span>(res.<span class="property">tempFilePaths</span>); <span class="comment">//得到路径图片路径</span></span><br><span class="line">	&#125;</span><br><span class="line">&#125;);</span><br><span class="line"></span><br><span class="line"><span class="comment">//通过  uni.uploadFile 传到自己的服务器</span></span><br><span class="line"></span><br></pre></td></tr></table></figure>
<h3 id="导航跳转"><a href="#导航跳转" class="headerlink" title="导航跳转"></a>导航跳转</h3><h4 id="组件-navigator"><a href="#组件-navigator" class="headerlink" title="组件 navigator"></a>组件 navigator</h4><p><a target="_blank" rel="noopener" href="https://uniapp.dcloud.io/component/navigator">navigator</a></p>
<figure class="highlight html"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br></pre></td><td class="code"><pre><span class="line"><span class="comment">&lt;!--open-type=&#x27;switchTab&#x27; 设置了才能跳转tabBar 页面--&gt;</span></span><br><span class="line"><span class="comment">&lt;!--open-type=&#x27;redirect&#x27; 替换到新页面 无返回--&gt;</span></span><br><span class="line"><span class="tag">&lt;<span class="name">navigator</span> <span class="attr">url</span>=<span class="string">&quot;pages/about/new_file&quot;</span> <span class="attr">hover-class</span>=<span class="string">&quot;navigator-hover&quot;</span> <span class="attr">open-type</span>=<span class="string">&#x27;switchTab&#x27;</span>&gt;</span></span><br><span class="line">	<span class="tag">&lt;<span class="name">button</span> <span class="attr">type</span>=<span class="string">&quot;default&quot;</span>&gt;</span>跳转到关于页面<span class="tag">&lt;/<span class="name">button</span>&gt;</span></span><br><span class="line"><span class="tag">&lt;/<span class="name">navigator</span>&gt;</span></span><br></pre></td></tr></table></figure>

<h4 id="路由跳转"><a href="#路由跳转" class="headerlink" title="路由跳转"></a>路由跳转</h4><p><a target="_blank" rel="noopener" href="https://uniapp.dcloud.io/api/router?id=navigateto">uni.navigateTo</a></p>
<figure class="highlight javascript"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br></pre></td><td class="code"><pre><span class="line">uni.<span class="title function_">navigateTo</span>(&#123;</span><br><span class="line">    <span class="attr">url</span>: <span class="string">&#x27;pages/about/new_file&#x27;</span></span><br><span class="line">&#125;);</span><br><span class="line"></span><br><span class="line"><span class="comment">//tabBar页面，并关闭其他非tabBar页面</span></span><br><span class="line">uni.<span class="title function_">switchTab</span>(&#123; </span><br><span class="line">    <span class="attr">url</span>: <span class="string">&#x27;pages/about/new_file&#x27;</span></span><br><span class="line">&#125;);</span><br><span class="line"></span><br><span class="line"><span class="comment">//替换到新页面</span></span><br><span class="line">uni.<span class="title function_">redirectTo</span>(&#123;</span><br><span class="line">    <span class="attr">url</span>: <span class="string">&#x27;xxx&#x27;</span></span><br><span class="line">&#125;);</span><br><span class="line"></span><br><span class="line"><span class="comment">//跳转通过?传的参数，通过生命周期onLoad获取参数</span></span><br><span class="line"></span><br><span class="line"></span><br></pre></td></tr></table></figure>

<h2 id="发行"><a href="#发行" class="headerlink" title="发行"></a>发行</h2><h2 id="HBuilderX-cli"><a href="#HBuilderX-cli" class="headerlink" title="HBuilderX cli"></a>HBuilderX cli</h2><p>命令行操作开发环境,安装好 HBuilderX 把bin路径配置到环境变量中</p>
<figure class="highlight shell"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br></pre></td><td class="code"><pre><span class="line"><span class="meta prompt_"># </span><span class="language-bash">打开编辑器</span></span><br><span class="line">cli.exe open</span><br><span class="line"><span class="meta prompt_"></span></span><br><span class="line"><span class="meta prompt_"># </span><span class="language-bash">登录</span></span><br><span class="line">cli.exe user login --username 869664233@qq.com  --password lzxxxxxxx</span><br><span class="line"><span class="meta prompt_"></span></span><br><span class="line"><span class="meta prompt_"># </span><span class="language-bash">退出</span></span><br><span class="line">cli user logout</span><br><span class="line"><span class="meta prompt_"></span></span><br><span class="line"><span class="meta prompt_"># </span><span class="language-bash">项目列表</span></span><br><span class="line">cli project list</span><br><span class="line"></span><br><span class="line"></span><br></pre></td></tr></table></figure></article><div class="post-copyright"><div class="post-copyright__author"><span class="post-copyright-meta">文章作者: </span><span class="post-copyright-info"><a href="http://example.com">lzoxun</a></span></div><div class="post-copyright__type"><span class="post-copyright-meta">文章链接: </span><span class="post-copyright-info"><a href="http://example.com/2023/07/22/web/web-app-uniapp/">http://example.com/2023/07/22/web/web-app-uniapp/</a></span></div><div class="post-copyright__notice"><span class="post-copyright-meta">版权声明: </span><span class="post-copyright-info">本博客所有文章除特别声明外，均采用 <a href="https://creativecommons.org/licenses/by-nc-sa/4.0/" target="_blank">CC BY-NC-SA 4.0</a> 许可协议。转载请注明来自 <a href="http://example.com" target="_blank">学习笔记</a>！</span></div></div><div class="tag_share"><div class="post-meta__tag-list"></div><div class="post_share"><div class="social-share" data-image="https://i.loli.net/2021/02/24/5O1day2nriDzjSu.png" data-sites="facebook,twitter,wechat,weibo,qq"></div><link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/butterfly-extsrc/sharejs/dist/css/share.min.css" media="print" onload="this.media='all'"><script src="https://cdn.jsdelivr.net/npm/butterfly-extsrc/sharejs/dist/js/social-share.min.js" defer></script></div></div><nav class="pagination-post" id="pagination"><div class="prev-post pull-left"><a href="/2023/07/22/web/web-app-uniapp-2023/" title="uni-app 2023"><div class="cover" style="background: var(--default-bg-color)"></div><div class="pagination-info"><div class="label">上一篇</div><div class="prev_info">uni-app 2023</div></div></a></div><div class="next-post pull-right"><a href="/2023/07/22/web/vue/vue-vuecli/" title=""><div class="cover" style="background: var(--default-bg-color)"></div><div class="pagination-info"><div class="label">下一篇</div><div class="next_info"></div></div></a></div></nav></div><div class="aside-content" id="aside-content"><div class="card-widget card-info"><div class="is-center"><div class="avatar-img"><img src= "" data-lazy-src="https://i.loli.net/2021/02/24/5O1day2nriDzjSu.png" onerror="this.onerror=null;this.src='/img/friend_404.gif'" alt="avatar"/></div><div class="author-info__name">lzoxun</div><div class="author-info__description"></div></div><div class="card-info-data site-data is-center"><a href="/archives/"><div class="headline">文章</div><div class="length-num">108</div></a><a href="/tags/"><div class="headline">标签</div><div class="length-num">1</div></a><a href="/categories/"><div class="headline">分类</div><div class="length-num">0</div></a></div><a id="card-info-btn" target="_blank" rel="noopener" href="https://github.com/liaozhongxun"><i class="fab fa-github"></i><span>Follow Me</span></a><div class="card-info-social-icons is-center"><a class="social-icon" href="https://github.com/liaozhongxun" target="_blank" title="Github"><i class="fab fa-github" style="color: #24292e;"></i></a><a class="social-icon" href="mailto:869664233@gmail.com" target="_blank" title="Email"><i class="fas fa-envelope" style="color: #4a7dbe;"></i></a></div></div><div class="card-widget card-announcement"><div class="item-headline"><i class="fas fa-bullhorn fa-shake"></i><span>公告</span></div><div class="announcement_content">这是我的文档</div></div><div class="sticky_layout"><div class="card-widget" id="card-toc"><div class="item-headline"><i class="fas fa-stream"></i><span>目录</span><span class="toc-percentage"></span></div><div class="toc-content"><ol class="toc"><li class="toc-item toc-level-2"><a class="toc-link" href="#%E5%BC%80%E5%90%AFuniapp"><span class="toc-number">1.</span> <span class="toc-text">开启uniapp</span></a><ol class="toc-child"><li class="toc-item toc-level-3"><a class="toc-link" href="#%E7%8E%AF%E5%A2%83%E6%90%AD%E5%BB%BA"><span class="toc-number">1.1.</span> <span class="toc-text">环境搭建</span></a></li><li class="toc-item toc-level-3"><a class="toc-link" href="#%E8%BF%90%E8%A1%8C"><span class="toc-number">1.2.</span> <span class="toc-text">运行</span></a></li><li class="toc-item toc-level-3"><a class="toc-link" href="#%E8%A7%84%E8%8C%83"><span class="toc-number">1.3.</span> <span class="toc-text">规范</span></a></li><li class="toc-item toc-level-3"><a class="toc-link" href="#%E6%9D%A1%E4%BB%B6%E6%B3%A8%E9%87%8A%E8%B7%A8%E7%AB%AF%E5%85%BC%E5%AE%B9"><span class="toc-number">1.4.</span> <span class="toc-text">条件注释跨端兼容</span></a></li></ol></li><li class="toc-item toc-level-2"><a class="toc-link" href="#%E7%9B%AE%E5%BD%95%E7%BB%93%E6%9E%84%E4%B8%8E%E9%A1%B9%E7%9B%AE%E9%85%8D%E7%BD%AE"><span class="toc-number">2.</span> <span class="toc-text">目录结构与项目配置</span></a><ol class="toc-child"><li class="toc-item toc-level-3"><a class="toc-link" href="#%E7%9B%AE%E5%BD%95%E7%BB%93%E6%9E%84"><span class="toc-number">2.1.</span> <span class="toc-text">目录结构</span></a></li><li class="toc-item toc-level-3"><a class="toc-link" href="#%E5%85%A8%E5%B1%80%E9%85%8D%E7%BD%AE"><span class="toc-number">2.2.</span> <span class="toc-text">全局配置</span></a></li><li class="toc-item toc-level-3"><a class="toc-link" href="#%E7%BB%84%E4%BB%B6"><span class="toc-number">2.3.</span> <span class="toc-text">组件</span></a><ol class="toc-child"><li class="toc-item toc-level-4"><a class="toc-link" href="#%E5%86%85%E7%BD%AE%E7%BB%84%E4%BB%B6"><span class="toc-number">2.3.1.</span> <span class="toc-text">内置组件</span></a></li><li class="toc-item toc-level-4"><a class="toc-link" href="#%E5%88%9B%E5%BB%BA%E7%BB%84%E4%BB%B6"><span class="toc-number">2.3.2.</span> <span class="toc-text">创建组件</span></a><ol class="toc-child"><li class="toc-item toc-level-5"><a class="toc-link" href="#%E7%BB%84%E4%BB%B6%E9%80%9A%E8%AE%AF"><span class="toc-number">2.3.2.1.</span> <span class="toc-text">组件通讯</span></a></li></ol></li></ol></li><li class="toc-item toc-level-3"><a class="toc-link" href="#uniapp%E4%B8%AD%E7%9A%84%E6%A0%B7%E5%BC%8F"><span class="toc-number">2.4.</span> <span class="toc-text">uniapp中的样式</span></a></li><li class="toc-item toc-level-3"><a class="toc-link" href="#%E6%95%B0%E6%8D%AE%E7%BB%91%E5%AE%9A%E4%BA%8B%E4%BB%B6%E2%80%A6"><span class="toc-number">2.5.</span> <span class="toc-text">数据绑定事件…</span></a></li><li class="toc-item toc-level-3"><a class="toc-link" href="#uni%E7%94%9F%E5%91%BD%E5%91%A8%E6%9C%9F"><span class="toc-number">2.6.</span> <span class="toc-text">uni生命周期</span></a><ol class="toc-child"><li class="toc-item toc-level-4"><a class="toc-link" href="#%E5%BA%94%E7%94%A8%E7%9A%84%E7%94%9F%E5%91%BD%E5%91%A8%E6%9C%9F"><span class="toc-number">2.6.1.</span> <span class="toc-text">应用的生命周期</span></a></li><li class="toc-item toc-level-4"><a class="toc-link" href="#%E9%A1%B5%E9%9D%A2%E7%9A%84%E7%94%9F%E5%91%BD%E5%91%A8%E6%9C%9F"><span class="toc-number">2.6.2.</span> <span class="toc-text">页面的生命周期</span></a></li><li class="toc-item toc-level-4"><a class="toc-link" href="#%E7%BB%84%E4%BB%B6%E7%9A%84%E7%94%9F%E5%91%BD%E5%91%A8%E6%9C%9F"><span class="toc-number">2.6.3.</span> <span class="toc-text">组件的生命周期</span></a></li></ol></li></ol></li><li class="toc-item toc-level-2"><a class="toc-link" href="#%E4%BA%A4%E4%BA%92"><span class="toc-number">3.</span> <span class="toc-text">交互</span></a><ol class="toc-child"><li class="toc-item toc-level-3"><a class="toc-link" href="#%E7%BD%91%E7%BB%9C%E8%AF%B7%E6%B1%82"><span class="toc-number">3.1.</span> <span class="toc-text">网络请求</span></a></li><li class="toc-item toc-level-3"><a class="toc-link" href="#%E6%95%B0%E6%8D%AE%E7%BC%93%E5%AD%98"><span class="toc-number">3.2.</span> <span class="toc-text">数据缓存</span></a></li><li class="toc-item toc-level-3"><a class="toc-link" href="#%E5%9B%BE%E7%89%87%E4%B8%8A%E4%BC%A0"><span class="toc-number">3.3.</span> <span class="toc-text">图片上传</span></a></li><li class="toc-item toc-level-3"><a class="toc-link" href="#%E5%AF%BC%E8%88%AA%E8%B7%B3%E8%BD%AC"><span class="toc-number">3.4.</span> <span class="toc-text">导航跳转</span></a><ol class="toc-child"><li class="toc-item toc-level-4"><a class="toc-link" href="#%E7%BB%84%E4%BB%B6-navigator"><span class="toc-number">3.4.1.</span> <span class="toc-text">组件 navigator</span></a></li><li class="toc-item toc-level-4"><a class="toc-link" href="#%E8%B7%AF%E7%94%B1%E8%B7%B3%E8%BD%AC"><span class="toc-number">3.4.2.</span> <span class="toc-text">路由跳转</span></a></li></ol></li></ol></li><li class="toc-item toc-level-2"><a class="toc-link" href="#%E5%8F%91%E8%A1%8C"><span class="toc-number">4.</span> <span class="toc-text">发行</span></a></li><li class="toc-item toc-level-2"><a class="toc-link" href="#HBuilderX-cli"><span class="toc-number">5.</span> <span class="toc-text">HBuilderX cli</span></a></li></ol></div></div><div class="card-widget card-recent-post"><div class="item-headline"><i class="fas fa-history"></i><span>最新文章</span></div><div class="aside-list"><div class="aside-list-item no-cover"><div class="content"><a class="title" href="/2023/07/22/window/win-11/" title="win 11 set">win 11 set</a><time datetime="2023-07-22T07:14:09.700Z" title="发表于 2023-07-22 15:14:09">2023-07-22</time></div></div><div class="aside-list-item no-cover"><div class="content"><a class="title" href="/2023/07/22/window/win-gitbash/" title="git bash">git bash</a><time datetime="2023-07-22T07:14:09.700Z" title="发表于 2023-07-22 15:14:09">2023-07-22</time></div></div><div class="aside-list-item no-cover"><div class="content"><a class="title" href="/2023/07/22/window/win-wsl/" title="wsl">wsl</a><time datetime="2023-07-22T07:14:09.700Z" title="发表于 2023-07-22 15:14:09">2023-07-22</time></div></div><div class="aside-list-item no-cover"><div class="content"><a class="title" href="/2023/07/22/window/win-main/" title="window">window</a><time datetime="2023-07-22T07:14:09.700Z" title="发表于 2023-07-22 15:14:09">2023-07-22</time></div></div><div class="aside-list-item no-cover"><div class="content"><a class="title" href="/2023/07/22/web/%E5%85%BC%E5%AE%B9%E9%97%AE%E9%A2%98/" title="兼容问题">兼容问题</a><time datetime="2023-07-22T07:14:09.699Z" title="发表于 2023-07-22 15:14:09">2023-07-22</time></div></div></div></div></div></div></main><footer id="footer"><div id="footer-wrap"><div class="copyright">&copy;2020 - 2023 By lzoxun</div><div class="framework-info"><span>框架 </span><a target="_blank" rel="noopener" href="https://hexo.io">Hexo</a><span class="footer-separator">|</span><span>主题 </span><a target="_blank" rel="noopener" href="https://github.com/jerryc127/hexo-theme-butterfly">Butterfly</a></div></div></footer></div><div id="rightside"><div id="rightside-config-hide"><button id="readmode" type="button" title="阅读模式"><i class="fas fa-book-open"></i></button><button id="translateLink" type="button" title="简繁转换">繁</button><button id="darkmode" type="button" title="浅色和深色模式转换"><i class="fas fa-adjust"></i></button><button id="hide-aside-btn" type="button" title="单栏和双栏切换"><i class="fas fa-arrows-alt-h"></i></button></div><div id="rightside-config-show"><button id="rightside_config" type="button" title="设置"><i class="fas fa-cog fa-spin"></i></button><button class="close" id="mobile-toc-button" type="button" title="目录"><i class="fas fa-list-ul"></i></button><button id="go-up" type="button" title="回到顶部"><span class="scroll-percent"></span><i class="fas fa-arrow-up"></i></button></div></div><div><script src="/js/utils.js"></script><script src="/js/main.js"></script><script src="/js/tw_cn.js"></script><script src="https://cdn.jsdelivr.net/npm/@fancyapps/ui/dist/fancybox/fancybox.umd.min.js"></script><script src="https://cdn.jsdelivr.net/npm/instant.page/instantpage.min.js" type="module"></script><script src="https://cdn.jsdelivr.net/npm/vanilla-lazyload/dist/lazyload.iife.min.js"></script><script src="https://cdn.jsdelivr.net/npm/node-snackbar/dist/snackbar.min.js"></script><script>function panguFn () {
  if (typeof pangu === 'object') pangu.autoSpacingPage()
  else {
    getScript('https://cdn.jsdelivr.net/npm/pangu/dist/browser/pangu.min.js')
      .then(() => {
        pangu.autoSpacingPage()
      })
  }
}

function panguInit () {
  if (false){
    GLOBAL_CONFIG_SITE.isPost && panguFn()
  } else {
    panguFn()
  }
}

document.addEventListener('DOMContentLoaded', panguInit)</script><div class="js-pjax"></div><script id="canvas_nest" defer="defer" color="0,0,255" opacity="0.7" zIndex="-1" count="99" mobile="false" src="https://cdn.jsdelivr.net/npm/butterfly-extsrc/dist/canvas-nest.min.js"></script><script async data-pjax src="//busuanzi.ibruce.info/busuanzi/2.3/busuanzi.pure.mini.js"></script><div id="local-search"><div class="search-dialog"><nav class="search-nav"><span class="search-dialog-title">搜索</span><span id="loading-status"></span><button class="search-close-button"><i class="fas fa-times"></i></button></nav><div class="is-center" id="loading-database"><i class="fas fa-spinner fa-pulse"></i><span>  数据库加载中</span></div><div class="search-wrap"><div id="local-search-input"><div class="local-search-box"><input class="local-search-box--input" placeholder="搜索文章" type="text"/></div></div><hr/><div class="no-result" id="local-search-results"></div><div id="local-search-stats-wrap"></div></div></div><div id="search-mask"></div><script src="/js/search/local-search.js"></script></div></div><script src="/live2dw/lib/L2Dwidget.min.js?094cbace49a39548bed64abff5988b05"></script><script>L2Dwidget.init({"pluginRootPath":"live2dw/","pluginJsPath":"lib/","pluginModelPath":"assets/","tagMode":false,"log":false,"model":{"jsonPath":"/live2dw/assets/haruto.model.json"},"display":{"position":"right","width":100,"height":200,"right":300},"mobile":{"show":true}});</script></body></html>